/// [Amicable numbers](https://projecteuler.net/problem=21)
fn main() {
    let length = 10000;
    let mut sum = 0;
    for i in 2..length {
        let j = d(i);
        if j != i && j < length && d(j) == i {
            sum += i;
        }
    }
    println!(
        "Evaluate the sum of all the amicable numbers under {} is {}",
        length, sum
    );
}

fn d(src: u64) -> u64 {
    let max = (src as f64).sqrt().floor() as u64;
    let mut sum = 1;
    for i in 2..=max {
        if src % i == 0 {
            sum += i;
            sum += src / i;
        }
    }
    sum
}
